package com.trg.generaltool.service.rabbitmq.topics;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.trg.generaltool.util.rabbitmq.RabbitmqUtil;

import java.io.IOException;

/**
 * @ClassName: TopicsProiider
 * @Description:    动态路由模型-生产者
 * @Author: tangrg
 * @Date: 2021/7/19 14:31
 * @Version: 1.0
 * @Return:
 **/
public class TopicsProiider {

    public static void main(String[] args) throws IOException {
        //获取连接
        Connection connect = RabbitmqUtil.getConnect();
        //创建通道
        Channel channel = connect.createChannel();
        //通道绑定交换机
        channel.exchangeDeclare("topics","topic");
        //发送消息
        String routeKey = "user.delete.dela";
        channel.basicPublish("topics",routeKey,null,(routeKey+" i am topics").getBytes());

        //关闭连接
        RabbitmqUtil.closeConnect(connect,channel);

    }
}
